package com.lz.ub.hm

/**
 * @author you
 * 蓝牙设备类 mac地址, 绑定的link地址, 属性值, 地址类型, 扩展
 */
class UBDevice internal constructor(val mac: String, val link: Int, val property: Int, val addType: Int, val tag: Any? = null) {

    var status: Int = STATUS_INIT
        internal set

    val connectCommand = "AT+CONN=$link,$addType,$mac\n"

    val propertyCommand = "AT+TXPORT=$link,$property\n"

    val disconnectCommand = "AT+DISCON=$link\n"

    fun isEnabled(): Boolean = status >= STATUS_SERVING

    fun isConnecting(): Boolean = status >= STATUS_CONNECTING

    fun close() {
        status = STATUS_INIT
    }

    override fun equals(other: Any?): Boolean {
        if (other === this) return true
        if (other is UBDevice) return other.mac == this.mac
        return false
    }

    override fun hashCode(): Int = link

    override fun toString(): String = "device ==> $mac, link = $link, property = $property, addType = $addType, status = $status"
}